package indi.zhifa.recipe.bailan.busy.auth.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.CompanyEntity;
import indi.zhifa.recipe.bailan.busy.auth.dao.mapper.CompanyMapper;
import indi.zhifa.recipe.bailan.busy.auth.dao.service.ICompanyDbService;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.DeptEntity;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.DeviceGroupEntity;
import indi.zhifa.recipe.bailan.framework.mysql.entity.annotations.ZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * <p>
 * 公司表 服务实现类
 * </p>
 *
 * @author 织法
 * @since 2023-01-08
 */

@ZfDbService(name = "CompanyEntity")
public class CompanyDbServiceImpl extends ZfDbServiceImpl<CompanyMapper, CompanyEntity> implements ICompanyDbService {
    @CacheEvict(cacheNames = "sys_company-authId",key = "#pAuthId")
    @Override
    public CompanyEntity deleteByAuthId(Long pAuthId) {
        LambdaQueryWrapper<CompanyEntity> queryWrapper = Wrappers.<CompanyEntity>lambdaQuery()
                .eq(CompanyEntity::getAuthId,pAuthId);
        CompanyEntity entity = findOne(queryWrapper);
        if(null != entity){
            removeById(entity.getId());
        }
        return entity;
    }

    @Override
    public CompanyEntity findByName(String pName) {
        LambdaQueryWrapper<CompanyEntity> queryWrapper = Wrappers.<CompanyEntity>lambdaQuery()
                .eq(CompanyEntity::getName,pName);
        return findOne(queryWrapper);
    }

    @Cacheable(cacheNames = "sys_company-authId",key = "#pAuthId",condition = "null != #result")
    @Override
    public CompanyEntity findByAuthId(Long pAuthId){
        LambdaQueryWrapper<CompanyEntity> queryWrapper = Wrappers.<CompanyEntity>lambdaQuery()
                .eq(CompanyEntity::getAuthId,pAuthId);
        CompanyEntity entity = findOne(queryWrapper);
        return entity;
    }
}
